<template>
	<view>
		<u-modal
			:show="isShow" 
			:title="modalTitle" 
			ref="proRef"
			:closeOnClickOverlay="true"
			@confirm="confirmHandle" 
			@close="closeHandle"
			>
			<u-radio-group
			    v-model="selectId"
			    placement="column"
			  >
			    <u-radio
			      :customStyle="{marginBottom: '8px'}"
			      v-for="(item, index) in list"
			      :key="index"
			      :label="item.realname"
			      :name="item.id"
			      @change="radioChange"
			    >
			    </u-radio>
			  </u-radio-group>
		</u-modal>
	</view>
</template>

<script>
	import { http } from '../../utils/utils';
	import wxApi from '../../utils/wxApi';
	import api from '../../utils/api';
	const app = getApp();
	export default {
		data() {
			return{
				isShow:false,
				userid:undefined,
				companyid:undefined,
				projectid:undefined,
				departmentid:undefined,
				modalTitle:'选择',
				list:[],
				selectId: undefined,
			}
		},
		methods:{
			show(item){
				console.log('itemmmmmmmm',item)
				let {companyid, projectid, userid,departmentid} = item;
				this.companyid = companyid;
				this.projectid = projectid;
				this.userid = userid;
				this.departmentid = departmentid;
				this.modalTitle = this.departmentid == 5?'选择设计师':'选择监理';
				this.isShow = true;
				this.getList()
			},
			
			/* 
			busstodesigner 业务流转到设计/designertojianli 设计流转到监理
			userid   用户ID
			projectid   项目ID
			sheji_userid 设计师用户ID / jianli_userid 监理用户ID
			 */
			async confirmHandle(){
				if(!this.selectId) return uni.$u.toast('请选择')
				let action = this.departmentid == 5?'busstodesigner':'designertojianli';
				let data = {
					action,
					userid: this.userid,
					projectid: this.projectid
				}
				this.departmentid == 5?data.sheji_userid = this.selectId:data.jianli_userid = this.selectId;
				console.log('提交~~~~~~~',data)
				const res = await http.post(api.default, { data })
				console.log('提交结果~~~',res)
				this.isShow = false
				this.$emit('proSubHandle')
			},
			
			/* 
				getdesignerlist  获取设计师列表/getjianlilist  获取监理列表
				userid  当前登录用户ID
				companyid 当前登录用户公司ID
			 */
			async getList(){
				let action = this.departmentid == 5?'getdesignerlist':'getjianlilist';
				let data = {
					action,
					userid: this.userid,
					companyid: this.companyid
				}
				const res = await http.post(api.default, { data })
				this.list = res.data.data
			},
			
			// 选择
			radioChange(n) {
				console.log('radioChange', n);
				this.selectId = n;
			},
			
			closeHandle(){
				this.isShow = false
			}
		}
	}
</script>

<style>
</style>